<div class="task_content"></div>
<script>
    const E = window.wangEditor;
    const editor = new E('.task_content');
    editor.config.menus = [
        'head',
        'fontName',
        'fontSize',
        'bold',
        'italic',
        'underline',
        'strikeThrough',
        'foreColor',
        'backColor',
        // 'justify',
        'lineHeight',
        // 'link',
        'emoticon',
        'image',
        'splitLine',
        'undo',
        'redo'
    ];
    editor.config.showFullScreen = false;
    editor.config.uploadImgAccept = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'];
    editor.config.showLinkImg = false;
    editor.config.placeholder = '';

    editor.config.fontNames = [
        {name:"{:__('黑体')}",value:"黑体"},
        {name:"{:__('仿宋')}",value:"仿宋"},
        {name:"{:__('楷体')}",value:"楷体"},
        {name:"{:__('标楷体')}",value:"标楷体"},
        {name:"{:__('华文仿宋')}",value:"华文仿宋"},
        {name:"{:__('华文楷体')}",value:"华文楷体"},
        {name:"{:__('宋体')}",value:"宋体"},
        {name:"{:__('微软雅黑')}",value:"微软雅黑"},
        {name:"Arial",value:"Arial"},
        {name:"Tahoma",value:"Tahoma"},
        {name:"Verdana",value:"Verdana"},
        {name:"Times New Roman",value:"Times New Roman"},
        {name:"Courier New",value:"Courier New"},
    ];
    editor.config.emotions = [
        {
            title:'emoji',
            type: 'emoji', // 'emoji' / 'image'
            // emoji 表情，content 是一个数组即可
            content: '😀 😃 😄 😁 😆 😅 😂 😊 😇 🙂 🙃 😉 😓 😪 😴 🙄 🤔 😬 🤐'.split(/\s/),
        }
    ];
    editor.config.justify = [
        {
            
        }
    ];
    // 富文本上传图片
    editor.config.customUploadImg = function (resultFiles, insertImgFn) {
        var formdata = new FormData();
        var img = resultFiles[0];
        if(img == '' || img == null || img == undefined ){
            layer.msg("{:__('请选择文件')}",{icon:2});
            return false;
        }
        formdata.append("file",img);
        formdata.append("token",token);
        formdata.append("file_type",'image');
       
        $.ajax({
            url:'/api/common/upload',
            type:'post',
            data:formdata,
            processData:false,
            contentType:false,
            success:function(ret){
                if(ret.code != 401 && ret.code != 1){
                    layer.msg(ret.msg,{icon:2});
                } else if(ret.code ==1){
                    layer.msg(ret.msg,{icon:1},function(){
                        if(ret['data']['file'] != '' && ret['data']['file'] != null && ret['data']['file'] != undefined){
                            insertImgFn(ret['data']['file']['file_path']);
                        }
                    });
                }
            }
        });
        
    }
    editor.config.uploadImgHooks = {
        success: function(xhr) {
            $(".task_sub dt dl div.task_content div.w-e-text p img").attr("width","50px");
        }
    }

    editor.create();
    $("div[data-title=标题]").attr("data-title","{:__('标题')}");
    $("div[data-title=字体]").attr("data-title","{:__('字体')}");
    $("div[data-title=加粗]").attr("data-title","{:__('加粗')}");
    $("div[data-title=斜体]").attr("data-title","{:__('斜体')}");
    $("div[data-title=下划线]").attr("data-title","{:__('下划线')}");
    $("div[data-title=删除线]").attr("data-title","{:__('删除线')}");
    $("div[data-title=文字颜色]").attr("data-title","{:__('文字颜色')}");
    $("div[data-title=背景色]").attr("data-title","{:__('背景色')}");
    $("div[data-title=对齐]").attr("data-title","{:__('对齐')}");
    $("div[data-title=序列]").attr("data-title","{:__('序列')}");
    $("div[data-title=缩进]").attr("data-title","{:__('缩进')}");
    $("div[data-title=行高]").attr("data-title","{:__('行高')}");
    $("div[data-title=链接]").attr("data-title","{:__('链接')}");
    $("div[data-title=表情]").attr("data-title","{:__('表情')}");
    $("div[data-title=图片]").attr("data-title","{:__('图片')}");
    $("div[data-title=分割线]").attr("data-title","{:__('分割线')}");
    $("div[data-title=撤销]").attr("data-title","{:__('撤销')}");
    $("div[data-title=恢复]").attr("data-title","{:__('恢复')}");
    $("div[data-title=字号]").attr("data-title","{:__('字号')}");

</script>